<?php
/**
 * Created by PhpStorm.
 * User: songs
 * Date: 2019/10/12
 * Time: 10:13
 */

namespace App\admin\TableView;


use App\admin\TableView\BaseClass\BaseViewList;
use App\Jobs\Fun;
use App\Models\Admin\ApilistModel;
use App\Models\MoneyBilModel;

class ShenheMoneyView extends BaseViewList
{

    public function get_model()
    {

        return new MoneyBilModel();
    }

    public $show_add = false; ///显示添加按钮
    /**
     * 是否显示删除按钮
     */
    public $show_delete = false;
    public $topTitle = '审核提现';
    public $PageSize = 10;

    public $breadcrumb = '<li><a href="/mcadmin">Home</a></li>
        <li><a href="javascript:;">审核提现</a></li>
        ';

    public $html = '';


    //  public $show_add = false; ///显示添加按钮

    /**
     * 获取表格的唯一名字
     */
    public function getName()
    {
        return 'MoneyBilModel';
    }


    /**
     * 需要继承,然后定义每行需要显示的数据格式
     */
    public function Labels()
    {
        return array(
            //   BaseViewList::Button_checkbox=>[],
            'id' => 40,
            'uid'=>50,
            'tixian_xingming'=>50,
            'tixian_zhanghu'=>50,
            'money' => 40,
            'out_trade_no' => 40,
            'out_trade_no_play' => 40,
            'status' => 40,
            'msg' => 40,
            'admin' => 40,
            'examine_time' => 40,
            BaseViewList::Button_control => [

                BaseViewList::Button_Edit,
                //   BaseViewList::Button_Delete

            ]
        );
    }

    /**
     * 对话框中的各个字段
     */
    public function dialog()
    {
        return array(

            array(
                'zd' => 'status',
                'type' => self::dialog_list,
                'data' => [
                    MoneyBilModel::status_fail => '拒绝',
                    MoneyBilModel::status_Success => '通过'
                ]
            ),
            array(
                'zd' => 'msg'
            ),
        );
    }

    /**
     * 方便继承,多一层过滤
     */
    public function ModelTohtml($key, $model)
    {
        if($key=='money'){
            return '¥'.$model->$key.'元';
        }
        if($key=='status'){
            return MoneyBilModel::getstatus($model->$key);
        }
        if($key=='examine_time'){
            return Fun::date($model->$key);
        }

        return parent::ModelTohtml($key, $model);
    }
    /**
     * 返回查询的条件
     */
    public function find() {
        $find = $this->get_model()->where([
            'type'=>MoneyBilModel::type_tixian
        ]);

        if (isset($_GET['submit']) && $_GET['submit'] == 'true') {
            $this->where($find);
        }

        $find->orderBy($this->get_primaryKey(),'DESC');
        return $find;
    }



    public function save_model($model){

        $this->errorMsg='为了闯哥钱的安全,目前提现审核是关闭状态';
        return false;


        if($model->type!=MoneyBilModel::type_tixian){
            $this->errorMsg='该模块只处理提现申请';
            return false;
        }


        if($model->status==MoneyBilModel::status_Success){
            if($model->out_trade_no_play){
                $this->errorMsg='已经提现过,无法再次修改';
                return false;
            }
           /// $this->errorMsg='该订单已经被设置为提现成功,无法再次修改';
            $Alipay=new \App\Utilities\Alipay();
            $order_id=$Alipay->makeOut($model->out_trade_no,
                $model->tixian_zhanghu,$model->tixian_xingming,$model->money,'美策平台用户提现'
            );
            if($order_id){
                $model->out_trade_no_play=$order_id;
                return true;
            }else{
                $this->errorMsg=$Alipay->errorMsg;
                return false;
            }


        }

        if($model->status==MoneyBilModel::status_fail||$model->status==MoneyBilModel::status_null){
            if($model->out_trade_no_play){
                $this->errorMsg='已经提现过,无法再次修改';
                return false;
            }else{
                return true;
            }
        }



        $this->errorMsg='未知错误';
        return false;
    }
}